package com.yanqu.road.server.cmd.manor;

import com.yanqu.road.pb.manor.ManorProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.manor.ManorModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

/**
 * @author ：zfr
 * @date ：2021/5/19 10:02
 */
@Cmd(code = GameProtocol.S_MANOR_OBJECT_UNLOCK, desc = "解锁庄园物件")
public class ManorObjectUnLockCmd extends AbstractCommand {
    private int id;
    private int type;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        ManorProto.ManorObjectUnLockReqMsg msg = ManorProto.ManorObjectUnLockReqMsg.parseFrom(packet.getBytes());
        id = msg.getId();
        type = msg.getType();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(ManorModule.class).unLock(id, type);
    }

    @Override
    public void sendData(GamePlayer player) {
        ManorProto.ManorObjectUnLockRespMsg.Builder respMsg = ManorProto.ManorObjectUnLockRespMsg.newBuilder();
        respMsg.setRet(ret);
        respMsg.setId(id);
        respMsg.setType(type);
        player.sendPacket(ClientProtocol.U_MANOR_OBJECT_UNLOCK, respMsg);
    }
}
